package br.com.hbt.thread;

public class SomeThread extends Thread {

    private static int x = 0;

    public static void main(String[] args) throws InterruptedException {

        SomeThread[] st = {
            new SomeThread(), new SomeThread(), new SomeThread(), new SomeThread(), new SomeThread(),
        };

        st[0].start();
        st[0].goNow();
        st[1].start();
        st[0].goNow();
        st[2].start();
        st[0].goNow();
        st[3].start();
        st[0].goNow();
        st[4].start();
        st[0].goNow();
        //        goNow();

    }

    @Override
    public void run() {
        try {
            Thread.sleep(1500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        goNow();
    }

    public synchronized void goNow() {
        x++;
        System.out.println(x);
    }

}
